{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import Union\n",
    "\n",
    "def get_input() -> Union[int, str, float]:\n",
    "    # 这个函数返回一个整数、字符串或浮点数\n",
    "    return input(\"请输入一个值: \")\n",
    "\n",
    "# 使用 Union\n",
    "user_input = get_input()\n",
    "print(type(user_input))  # 输出用户输入值的类型\n",
    "\n",
    "# 你可以在函数中根据 Union 类型提示来处理不同类型的输入\n",
    "def process_input(value: Union[int, str, float]) -> None:\n",
    "    if isinstance(value, int):\n",
    "        print(f\"你输入了一个整数: {value}\")\n",
    "    elif isinstance(value, str):\n",
    "        print(f\"你输入了一个字符串: {value}\")\n",
    "    elif isinstance(value, float):\n",
    "        print(f\"你输入了一个浮点数: {value}\")\n",
    "\n",
    "# 调用函数\n",
    "process_input(user_input)"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
